/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.oracleandsxnd.erp.xsd.web;

import com.oracleandsxnd.erp.common.persistence.Page;
import com.oracleandsxnd.erp.common.persistence.TableSplitResult;
import com.oracleandsxnd.erp.common.utils.StringUtils;
import com.oracleandsxnd.erp.common.web.AjaxResult;
import com.oracleandsxnd.erp.common.web.BaseController;
import com.oracleandsxnd.erp.seting.entity.Company;
import com.oracleandsxnd.erp.seting.entity.Logistics;
import com.oracleandsxnd.erp.seting.service.CompanyService;
import com.oracleandsxnd.erp.seting.service.LogisticsService;
import com.oracleandsxnd.erp.xsd.entity.XsglSale;
import com.oracleandsxnd.erp.xsd.entity.XsglSaleDetail;
import com.oracleandsxnd.erp.xsd.entity.XsglSaleType;
import com.oracleandsxnd.erp.xsd.service.XsglSaleService;
import com.oracleandsxnd.erp.xsd.service.XsglSaleTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 销售单Controller
 * @author 销售单
 * @version 2019-12-16
 */
@Controller
@RequestMapping(value = "xsd_xsglSale")
public class XsglSaleController extends BaseController {
	@Autowired
	private CompanyService companyService;
	@Autowired
	private XsglSaleService xsglSaleService;

	@Autowired
	private LogisticsService logisticsService;
	@RequestMapping(value = {""})
	public String list(Model model) {

		return "erp/xsd/xsglSaleList";
	}
	@RequestMapping(value = {"listData"})
	@ResponseBody
	public Object listData(XsglSale xsglSale , HttpServletRequest request, HttpServletResponse response){
		Page<XsglSale> page = xsglSaleService.findPage(new Page<XsglSale>(request, response), xsglSale);
		TableSplitResult<XsglSale> result=new TableSplitResult<XsglSale>(page.getPageNo(), page.getCount(), page.getList());
		return  result;
	}

	@Autowired
	private XsglSaleTypeService xsglSaleTypeService;

	@RequestMapping(value = "form")
	public String form(String id, Model model) {
		XsglSale xsglSale=null;
			if (StringUtils.isNotBlank(id)){
				xsglSale = xsglSaleService.get(id);
			}
		if (xsglSale == null){
			xsglSale = new XsglSale();
		}
		Company c=new Company();
		c.setType("1");
		model.addAttribute("companys",companyService.findList(c));
		model.addAttribute("logistics",logisticsService.findList(new Logistics()));
		model.addAttribute("kinds",xsglSaleTypeService.findList(new XsglSaleType()));
		model.addAttribute("xsglSale",xsglSale);
		return "erp/xsd/xsglSaleForm";
	}


	@RequestMapping(value = "save")
	public String save(XsglSale xsglSale) {

		xsglSaleService.save(xsglSale);
		return "redirect:/xsd_xsglSale/form";

	}

	@RequestMapping(value = "delete")
	@ResponseBody
	public AjaxResult  delete(XsglSale xsglSale, RedirectAttributes redirectAttributes) {
		xsglSaleService.delete(xsglSale);
		return success();
	}

	@RequestMapping(value = {"mx"})
	public String mx(Model model) {
		return "erp/xsd/xsglSalemxList";
	}
	@RequestMapping(value = {"mxlistData"})
	@ResponseBody
	public Object mxlistData(XsglSaleDetail xsglSale , HttpServletRequest request, HttpServletResponse response){

		Page<XsglSaleDetail> page = xsglSaleService.findDPage(new Page<XsglSaleDetail>(request, response), xsglSale);
		TableSplitResult<XsglSaleDetail> result=new TableSplitResult<XsglSaleDetail>(page.getPageNo(), page.getCount(), page.getList());
		return  result;
	}
	@RequestMapping(value = {"xsmx"})
	public String xsmx(Model model) {
		return "erp/xsd/xsglSalexsmxList";
	}





	@RequestMapping(value = {"tj"})
	public String tj(Model model) {
		return "erp/xsd/xsglSaletjList";
	}
	@RequestMapping(value = {"tjlistData"})
	@ResponseBody
	public Object tjlistData(XsglSaleDetail xsglSale , HttpServletRequest request, HttpServletResponse response){

		Page<XsglSaleDetail> page = xsglSaleService.findtjPage(new Page<XsglSaleDetail>(request, response), xsglSale);
		TableSplitResult<XsglSaleDetail> result=new TableSplitResult<XsglSaleDetail>(page.getPageNo(), page.getCount(), page.getList());
		return  result;
	}
	@RequestMapping(value = {"xstj"})
	public String xstj(Model model) {
		return "erp/xsd/xsglSalexstjList";
	}

	@RequestMapping(value = {"profittj"})
	public String profittj(Model model) {
		return "erp/xsd/xsglSaleprofittjList";
	}
	@RequestMapping(value = {"profittjlistData"})
	@ResponseBody
	public Object profittjlistData(XsglSaleDetail xsglSale , HttpServletRequest request, HttpServletResponse response){

		Page<XsglSaleDetail> page = xsglSaleService.findtjPage(new Page<XsglSaleDetail>(request, response), xsglSale);
		TableSplitResult<XsglSaleDetail> result=new TableSplitResult<XsglSaleDetail>(page.getPageNo(), page.getCount(), page.getList());
		return  result;
	}

}